package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyVendorPerformance;
import com.ruoyi.pims.service.IRyVendorPerformanceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商绩效Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/performance")
public class RyVendorPerformanceController extends BaseController
{
    private String prefix = "pims/performance";

    @Autowired
    private IRyVendorPerformanceService ryVendorPerformanceService;

    @RequiresPermissions("pims:performance:view")
    @GetMapping()
    public String performance()
    {
        return prefix + "/performance";
    }

    /**
     * 查询供应商绩效列表
     */
    @RequiresPermissions("pims:performance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyVendorPerformance ryVendorPerformance)
    {
        startPage();
        List<RyVendorPerformance> list = ryVendorPerformanceService.selectRyVendorPerformanceList(ryVendorPerformance);
        return getDataTable(list);
    }

    /**
     * 导出供应商绩效列表
     */
    @RequiresPermissions("pims:performance:export")
    @Log(title = "供应商绩效", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyVendorPerformance ryVendorPerformance)
    {
        List<RyVendorPerformance> list = ryVendorPerformanceService.selectRyVendorPerformanceList(ryVendorPerformance);
        ExcelUtil<RyVendorPerformance> util = new ExcelUtil<RyVendorPerformance>(RyVendorPerformance.class);
        return util.exportExcel(list, "供应商绩效数据");
    }

    /**
     * 新增供应商绩效
     */
    @RequiresPermissions("pims:performance:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商绩效
     */
    @RequiresPermissions("pims:performance:add")
    @Log(title = "供应商绩效", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyVendorPerformance ryVendorPerformance)
    {
        return toAjax(ryVendorPerformanceService.insertRyVendorPerformance(ryVendorPerformance));
    }

    /**
     * 修改供应商绩效
     */
    @RequiresPermissions("pims:performance:edit")
    @GetMapping("/edit/{performanceId}")
    public String edit(@PathVariable("performanceId") Long performanceId, ModelMap mmap)
    {
        RyVendorPerformance ryVendorPerformance = ryVendorPerformanceService.selectRyVendorPerformanceByPerformanceId(performanceId);
        mmap.put("ryVendorPerformance", ryVendorPerformance);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商绩效
     */
    @RequiresPermissions("pims:performance:edit")
    @Log(title = "供应商绩效", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyVendorPerformance ryVendorPerformance)
    {
        return toAjax(ryVendorPerformanceService.updateRyVendorPerformance(ryVendorPerformance));
    }

    /**
     * 删除供应商绩效
     */
    @RequiresPermissions("pims:performance:remove")
    @Log(title = "供应商绩效", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryVendorPerformanceService.deleteRyVendorPerformanceByPerformanceIds(ids));
    }
}
